package day3.LC349;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {

    }
}


class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        //令nums1.length<=nums2.length
        if (nums1.length > nums2.length) {
            int[] arrTemp = nums1;
            nums1=nums2;
            nums2=arrTemp;
        }
       //求交集
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                if (nums1[i] == nums2[j]) {
                    arrayList.add(nums1[i]);
                    break;
                }
            }
        }
        List<Integer> arr = arrayList.stream().distinct().collect(Collectors.toList());
        //返回
        int[] intersection = new int[arr.size()];
        for (int i = 0; i < arr.size(); i++) {
            intersection[i]=arr.get(i);
        }
        return intersection;
    }
}